//
//  VillageIntroduceVC.m
//  Cunli
//
//  Created by ZhanyaaLi on 16/1/6.
//  Copyright © 2016年 lilubin. All rights reserved.
//

#import "VillageIntroduceVC.h"
#import "UIViewExt.h"
#import "MyDataService.h"
#import "NSString+MD5.h"
#import "Config.h"

#define kScreenWidth [UIScreen mainScreen].bounds.size.width
#define kScreenHeight [UIScreen mainScreen].bounds.size.height

@interface VillageIntroduceVC () <UIWebViewDelegate, UIScrollViewDelegate>
{

}
@property (nonatomic, strong) UIWebView *detailWebView;   //新闻详情webview

@end

@implementation VillageIntroduceVC

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"本村介绍";
    [self setAttributeAboutWebView];
    [self loadIntroduceData];
    [self.view setBackgroundColor:[UIColor orangeColor]];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)setAttributeAboutWebView
{
    CGRect newFrame = self.view.frame;
    CGFloat newHeight = newFrame.size.height-64;
    newFrame.size.height = newHeight;
#pragma mark - old fun
    _detailWebView = [[UIWebView alloc] initWithFrame:newFrame];
    _detailWebView.delegate = self;
    _detailWebView.scrollView.delegate = self;
    _detailWebView.scrollView.bounces = NO;
    _detailWebView.translatesAutoresizingMaskIntoConstraints = NO;
    [self.view addSubview:_detailWebView];
}

- (void)loadIntroduceData
{
    NSMutableDictionary *CheckParams = [NSMutableDictionary dictionaryWithCapacity:3];
    [CheckParams setObject:[Config getOwnUserID] forKey:@"userid"];
    [CheckParams setObject:[Config getOwnAreaids] forKey:@"areaids"];
    NSString *resultSign = [NSString getSignFromParam:CheckParams andSession:[Config getOwnSession]];
    [CheckParams setObject:resultSign forKey:@"sign"];
    
    [MyDataService requestURL:@"getinfo_intro.php" httpMethod:@"GET" params:CheckParams fileDatas:nil complection:^(id result) {
        NSLog(@"VillageIntroduceResult:%@", result);
        
        if ([result[@"response"] isEqualToString:@"getinfo_intro"]) {
            
            NSDictionary *dataDic = result[@"data"];
            NSString *contentStr = dataDic[@"content"];
            NSArray *imgs = dataDic[@"big_pics"];
            NSMutableString *imageHtml = [NSMutableString string];
            NSString *pef = @"100%";
            NSString *htmlStr;
            for(NSString *imgURL in imgs)
            {
                [imageHtml appendString:[NSString stringWithFormat:@"<img src='%@' style = 'margin-bottom:5px;' width = %@><br />", imgURL, pef]];
            }
            
            htmlStr = [NSString stringWithFormat:@"<html><body><h2 align='center' style='margin-top:20px;'>%@</h3><div>%@</div><p align='left' style='color:#777777; margin-top:10px;'>%@</p><br/></body></html>", [Config getVillageName], contentStr, imageHtml];
            [_detailWebView loadHTMLString:htmlStr baseURL:nil];
        }
    } failureAction:^{
        
    }];
}


@end
